package de.hska.algo.labor2010.strecken;

import java.util.ArrayList;
import java.util.List;

public class GridPart {
	private Point lowerLeft;
	private Point upperRight;
	private Boolean thisLineisInside;
	private ArrayList<Line> lines;
	private ArrayList<GridPart> neighbors;

	public ArrayList<GridPart> getNeighbors() {
		return neighbors;
	}



	public Point getLowerLeft() {
		return lowerLeft;
	}

	

	public Point getUpperRight() {
		return upperRight;
	}

	

	public Boolean getThisLineisInside() {
		return thisLineisInside;
	}

	public void setThisLineisInside(Boolean thisLineisInside) {
		this.thisLineisInside = thisLineisInside;
	}

	public ArrayList<Line> getLines() {
		return lines;
	}

	

	GridPart(double left, double bottom, double right, double top) {
		lowerLeft = new Point(left, bottom);
		upperRight = new Point(right, top);
		lines = new ArrayList<Line>();
		neighbors = new ArrayList<GridPart>();
	}

	public void addLine(Line line) {
		lines.add(line);
	}

	/*public void addNeighbour(GridPart part) {
		this.neighbours.add(part);
	}*/

	public boolean isPointInGridPart(Point p) {
		if (p.getX()  >= lowerLeft.getX() && p.getX()  < upperRight.getX()
				&& p.getY() >= lowerLeft.getY() && p.getY() < upperRight.getY()) {
			return true;
		} else
			return false;
	}

	public List<Point> findIntersections() {
		List<Point> result = new ArrayList<Point>();
		IntersectLinesBruteForce intersect = new IntersectLinesBruteForce();
		List<Point> intersections = intersect.bruteForceIntersect(lines);
		for (Point point : intersections) {
			if (isPointInGridPart(point)) {
				result.add(point);
			}
		}
		return result;
	}
	
	public String toString(){
		String grid = new String();
		grid+= "from " + lowerLeft.toString();
		grid+= " to " + upperRight.toString() + "\n";
		grid += "Lines:\n";
		for (Line line : lines) {
			grid += line.toString();
			
		}
		return grid;
	}
	public void addNeighbor(GridPart part){
		neighbors.add(part);
	}

}
